<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="avatar" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{avatarHome.managed ? 'Edit' : 'Add'} Avatar</f:facet>




            <s:decorate id="nameField" template="layout/edit.xhtml">
                <ui:define name="label">Name</ui:define>
                <h:inputText id="name"
                       required="true"
                           size="100"
                      maxlength="100"
                          value="#{avatarHome.instance.name}">
                    <a:support event="onblur" reRender="nameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="imageField" template="layout/edit.xhtml">
                <ui:define name="label">Image</ui:define>
                <h:inputText id="image"
                       required="true"
                          value="#{avatarHome.instance.image}">
                    <a:support event="onblur" reRender="imageField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="formatField" template="layout/edit.xhtml">
                <ui:define name="label">Format</ui:define>
                <h:inputText id="format"
                       required="true"
                           size="20"
                      maxlength="20"
                          value="#{avatarHome.instance.format}">
                    <a:support event="onblur" reRender="formatField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="typeField" template="layout/edit.xhtml">
                <ui:define name="label">Type</ui:define>
                <h:inputText id="type"
                       required="true"
                           size="10"
                      maxlength="10"
                          value="#{avatarHome.instance.type}">
                    <a:support event="onblur" reRender="typeField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{avatarHome.persist}"
                       disabled="#{!avatarHome.wired}"
                       rendered="#{!avatarHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{avatarHome.update}"
                       rendered="#{avatarHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{avatarHome.remove}"
                      immediate="true"
                       rendered="#{avatarHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Avatar.xhtml"
                rendered="#{avatarHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty avatarFrom ? 'AvatarList' : avatarFrom}.xhtml"
                rendered="#{!avatarHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="User *" labelClass="required">
    <div class="association" id="userParent">

        <h:outputText value="There is no user associated with this avatar."
                   rendered="#{avatarHome.instance.user == null}"/>

        <rich:dataTable var="_user"
                   value="#{avatarHome.instance.user}"
                rendered="#{avatarHome.instance.user != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="userTable">
            <h:column>
                <f:facet name="header">Id user</f:facet>
                <h:outputText value="#{_user.idUser}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Login</f:facet>
                <h:outputText value="#{_user.login}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Password</f:facet>
                <h:outputText value="#{_user.password}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Name</f:facet>
                <h:outputText value="#{_user.name}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Surname</f:facet>
                <h:outputText value="#{_user.surname}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Birth date</f:facet>
                <h:outputText value="#{_user.birthDate}">
                    <s:convertDateTime type="date" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Create date</f:facet>
                <h:outputText value="#{_user.createDate}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Modify date</f:facet>
                <h:outputText value="#{_user.modifyDate}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Delete date</f:facet>
                <h:outputText value="#{_user.deleteDate}">
                    <s:convertDateTime type="both" dateStyle="short"/>
                </h:outputText>
            </h:column>
            <h:column>
                <f:facet name="header">Type</f:facet>
                <h:outputText value="#{_user.type}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Calculated rate</f:facet>
                <h:outputText value="#{_user.calculatedRate}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Enabled</f:facet>
                <h:outputText value="#{_user.enabled}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{avatarHome.instance.user != null ? 'changeParent' : 'selectParent'}" value="#{avatarHome.instance.user != null ? 'Change' : 'Select'} user"
                       view="/UserList.xhtml">
                <f:param name="from" value="AvatarEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
